package cn.exempale.mscapplication.viewModel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import cn.exempale.mscapplication.dto.PrepareUploadDTO;
import cn.exempale.mscapplication.dto.TaskDTO;
import cn.exempale.mscapplication.model.repository.FileRepository;
import cn.exempale.mscapplication.model.repository.NormalRepository;
import cn.exempale.mscapplication.model.net.callback.Resource;
import cn.exempale.mscapplication.utils.JsonUtils;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class UploadViewModel extends AndroidViewModel {

    private NormalRepository normalRepository;
    private FileRepository fileRepository;

    public UploadViewModel(@NonNull Application application) {
        super(application);
        this.normalRepository = NormalRepository.newInstance();
        this.fileRepository = FileRepository.newInstance();
    }

    /**
     * 预上传
     */
    public LiveData<Resource> prepareUpload(PrepareUploadDTO dto) {
        return new MutableLiveData<>();
//        return normalRepository.prepareUpload(JsonUtils.Obj2Map(dto));
    }

    /**
     * 上传
     */

    public Resource upload(Map<String, RequestBody> map, MultipartBody.Part file) {
        return fileRepository.upLoad(map, file);
    }

    /**
     * 合并分片
     */
    public Resource marge(TaskDTO dto) {
        return normalRepository.merge(JsonUtils.Obj2Map(dto));
    }
}
